from rest_framework import serializers
from rest_framework.serializers import ModelSerializer

from orders.models import *

# 订单信息
class OrderInfo_Serializer(ModelSerializer):
    user_name = serializers.SerializerMethodField(read_only=True)

    def get_user_name(self, obj):
        return obj.user.username

    status_name = serializers.SerializerMethodField(read_only=True)

    # 获取 status支付状态的字符串信息  获取到选项对应了的文本信息
    def get_status_name(self, obj):
        return obj.get_status_display()

    class Meta:
        model = OrderInfo
        fields = '__all__'
        read_only_fields = ['id', ]


# 订单商品
class OrderGood_Serializer(ModelSerializer):

    class Meta:
        model = OrderGood
        fields = '__all__'
        read_only_fields = ['id', ]











